//
// Created by 11510 on 2024/6/21.
//
#include <iostream>
#include <string>
#include <memory>
#include <vector>

using namespace std;

void test1() {
    shared_ptr<int> sp(new int(8));
    weak_ptr<int> wp(sp);   /* 不可直接访问指向的资源 */

    cout << *sp << endl;

    weak_ptr<int> wp2 = sp;
    cout << wp.use_count() << endl;
    cout << wp2.use_count() << endl;

    shared_ptr<int> sp2 = wp2.lock();
    if(sp2){
        cout << "提升成功，管理的空间还在" << endl;
        cout << *sp << endl;
    }else{
        cout << "提升不成功，没有管理的空间" << endl;
    }
    /**wp2;*/
    cout << wp2.use_count() << endl;

    /* 判断管理的空间是否还存活 */
    wp.expired();
}

int main() {
    test1();
    return 0;
}